//
//  YQArticleListHeader.m
//  iyuanqi
//
//  Created by czl on 2017/7/28.
//  Copyright © 2017年 czl. All rights reserved.
//

#import "YQArticleListHeader.h"

@interface YQArticleListHeader ()

@property(nonatomic,strong)UIImageView* imageForumAvatar;
@property(nonatomic,strong)UILabel* labelForumName;
@property(nonatomic,strong)UILabel* labelTodayPost;
@property(nonatomic,strong)UILabel* labelMembers;

@end

@implementation YQArticleListHeader

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.imageForumAvatar];
        [self.imageForumAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(10);
            make.size.mas_equalTo(80);
        }];
        
        [self addSubview:self.labelForumName];
        [self.labelForumName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.imageForumAvatar.mas_right).offset(10);
            make.top.mas_equalTo(self.imageForumAvatar);
        }];
        
        [self addSubview:self.labelMembers];
        [self.labelMembers mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.labelForumName);
            make.bottom.mas_equalTo(self.imageForumAvatar);
        }];
        
        [self addSubview:self.labelTodayPost];
        [self.labelTodayPost mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.labelForumName);
            make.bottom.mas_equalTo(self.labelMembers.mas_top).offset(-5);
        }];
    }
    return self;
}

- (void)setForumObject:(YQForumObject *)forumObject {
    _forumObject = forumObject;
    
    [self.imageForumAvatar sd_setImageWithURL:[NSURL URLWithString:forumObject.icon] placeholderImage:[UIImage imageNamed:@"loadimage"]];
    self.labelForumName.text = forumObject.name;
    self.labelTodayPost.text = [NSString stringWithFormat:@"今日发布:%zd",forumObject.todayposts];
}

- (UIImageView*)imageForumAvatar {
    if (!_imageForumAvatar) {
        _imageForumAvatar = [[UIImageView alloc]init];
        _imageForumAvatar.image = [UIImage imageNamed:@"loadimage"];
        _imageForumAvatar.clipsToBounds = YES;
        _imageForumAvatar.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _imageForumAvatar;
}

- (UILabel*)labelForumName {
    if (!_labelForumName) {
        _labelForumName = [UILabel new];
        _labelForumName.font = [UIFont systemFontOfSize:20];
    }
    return _labelForumName;
}

- (UILabel*)labelTodayPost {
    if (!_labelTodayPost) {
        _labelTodayPost = [UILabel new];
        _labelTodayPost.font = [UIFont systemFontOfSize:12];
        _labelTodayPost.text = @"今日发布:";
    }
    return _labelTodayPost;
}

- (UILabel*)labelMembers {
    if (!_labelMembers) {
        _labelMembers = [UILabel new];
        _labelMembers.font = [UIFont systemFontOfSize:12];
        _labelMembers.text = @"成员:";
    }
    return _labelMembers;
}

@end
